home *** CD-ROM | disk | FTP | other *** search
- {****************************************************************************}
- {* *}
- {* UNIT PATHID (PATHID.PAS) *}
- {* *}
- {* Donated to the Public Domain 5/20/91 by Dan Thomas CIS: 72301,2164 *}
- {* *}
- {* This unit contains two routines: *}
- {* *}
- {* Split out the path from a file spec. *}
- {* Combine a path and file ID. *}
- {* *}
- {****************************************************************************}
-
-
- UNIT PATHID;
-
-
- {============================================================================}
- INTERFACE
-
- CONST
- ok_to_default = true;
- dont_default = false;
-
- PROCEDURE SPLIT_PATH_AND_FILE_ID(file_spec : string;
- var path, file_id : string;
- default_to_curr_directory : boolean);
- FUNCTION PATH_PLUS_FILE_ID(path, file_id : string) : string;
-
- {============================================================================}
- IMPLEMENTATION
-
- PROCEDURE SPLIT_PATH_AND_FILE_ID(file_spec : string;
- var path, file_id : string;
- default_to_curr_directory : boolean);
-
- var
- d,s,p,c : string;
- x : byte;
-
- begin
- s := file_spec;
- for x := 1 to length(s) do
- s[x] := upcase(s[x]);
- if (length(s) > 2) and (s[2] = ':') then
- begin
- d := copy(s,1,2);
- delete(s,1,2);
- end
- else
- d := '';
- x := pos('\',s);
- if x > 0 then
- begin
- x := length(s);
- while (x > 1) and (s[x] <> '\') do
- dec(x);
- if x = 1 then
- p := '\'
- else
- p := copy(s,1,x-1);
- delete(s,1,x);
- end
- else
- p := '';
- if ((p = '') or (p[1] <> '\')) and default_to_curr_directory then
- begin
- if d = '' then
- GetDir(0,c)
- else
- GetDir(ord(d[1]) - 64,c);
- d := copy(c,1,2);
- if p = '' then
- p := copy(c,3,length(c))
- else
- p := copy(c,3,length(c)) + '\' + p;
- if copy(p,1,2) = '\\' then
- delete(p,1,1);
- end;
- path := d + p;
- file_id := s;
- end; {split_path_and_id}
-
- FUNCTION PATH_PLUS_FILE_ID(path, file_id : string) : string;
-
- var
- d,s : string;
- x : byte;
-
- begin
- s := path;
- if (length(s) > 1) and (s[2] = ':') then
- begin
- d := copy(s,1,2);
- delete(s,1,2);
- end
- else
- d := '';
- while (s <> '') and (s[length(s)] = ' ') do
- delete(s,length(s),1);
- if (s = '\') or (s = '') then
- begin end
- else
- if s[length(s)] <> '\' then
- s := s + '\';
- s := d + s + file_id;
- for x := 1 to length(s) do
- s[x] := upcase(s[x]);
- path_plus_file_id := s;
- end; {path_plus_file_id}
-
- end.
-